package com.example.socialwebserver.controller;

import com.example.socialwebserver.pojo.*;
import com.example.socialwebserver.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class MessageController {

    @Autowired
    MessageService messageService;

    @RequestMapping("/message/selectNotRead")
    public ServerResult selectNotRead(CommunicateDTO communicateDTO)
    {
        List<MessageVO> messageVOS = messageService.selectNotRead(communicateDTO);
        return new ServerResult(0,"未读消息显示",messageVOS);
    }

    @RequestMapping("/message/selectAll")
    public ServerResult selectAll(CommunicateDTO communicateDTO)
    {
        List<MessageVO> messageVOS = messageService.selectAll(communicateDTO);
        return new ServerResult(0,"全部消息显示",messageVOS);

    }

    @RequestMapping("/message/insertMessage")
    public ServerResult insertMessage(MessageDTO messageDTO)
    {
        boolean res = messageService.insertMessage(messageDTO);
        ServerResult serverResult;
        if(res)
        {
            serverResult = new ServerResult(0, "信息发送成功", null);
        }
        else {
            serverResult = new ServerResult(101, "信息发送失败", null);
        }
        return serverResult;
    }
}
